package com.ziyia.recyclerviewtest;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private List<Fruit> fruits = new ArrayList<>();

    private RecyclerView recyclerView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerView = findViewById(R.id.recyclerView);
        initFruits();
//        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
//        layoutManager.setOrientation(RecyclerView.HORIZONTAL);
//        FruitAdapter adapter = new FruitAdapter(fruits);
//        recyclerView.setLayoutManager(layoutManager);
//        recyclerView.setAdapter(adapter);

        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(staggeredGridLayoutManager);
        recyclerView.setAdapter(new FruitAdapter(fruits));
    }

    private void initFruits() {
        for (int i = 0; i < 4; i++) {
//            fruits.add(new Fruit("Apple", R.drawable.apple_pic));
//            fruits.add(new Fruit("Banana", R.drawable.banana_pic));
//            fruits.add(new Fruit("Watermelon", R.drawable.watermelon_pic));
//            fruits.add(new Fruit("Pear", R.drawable.pear_pic));
//            fruits.add(new Fruit("Grape", R.drawable.grape_pic));
//            fruits.add(new Fruit("Pineapple", R.drawable.pineapple_pic));
//            fruits.add(new Fruit("Strawberry", R.drawable.strawberry_pic));
//            fruits.add(new Fruit("Cherry", R.drawable.cherry_pic));
//            fruits.add(new Fruit("Mango", R.drawable.mango_pic));
            fruits.add(new Fruit("AppleAppleApple Apple Apple AppleApple", R.drawable.apple_pic));
            fruits.add(new Fruit("BananaBananaBanana Banana BananaBanana ", R.drawable.banana_pic));
            fruits.add(new Fruit("WatermelonWatermelon Watermelon Watermelon WatermelonWatermelon ", R.drawable.watermelon_pic));
            fruits.add(new Fruit("PearPearPearPear Pear Pear Pear", R.drawable.pear_pic));
            fruits.add(new Fruit("GrapeGrapeGrape Grape Grape Grape Grape", R.drawable.grape_pic));
            fruits.add(new Fruit("PineapplePineapple Pineapple PineapplePineapplePineapple Pineapple ", R.drawable.pineapple_pic));
            fruits.add(new Fruit("Strawberry Strawberry Strawberry StrawberryStrawberry Strawberry Strawberry ", R.drawable.strawberry_pic));
            fruits.add(new Fruit("Cherry Cherry Cherry Cherry CherryCherryherry ", R.drawable.cherry_pic));
            fruits.add(new Fruit("Mango Mango Mango Mango Mango Mango", R.drawable.mango_pic));
        }
    }
}